package com.wjerp.tplus.server.common.security;

import com.fasterxml.jackson.annotation.JsonIgnore;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;

/**
 * @author lishuailei
 */
public class JwtUser implements UserDetails {

    /**
	 * 
	 */
	private static final Long serialVersionUID = 1L;
	
	private final Long id;
	private final String displayUserId;
    private final String username;
    private final String password;
    private final Integer userType;
    private final Collection<? extends GrantedAuthority> authorities;
    private final boolean enabled;
    private final String companyCode;

    public JwtUser(
            Long id,
            String displayUserId,
            String username,
            String password,
            Integer userType,
            Collection<? extends GrantedAuthority> authorities,
            boolean enabled,
            String companyCode) {
        this.displayUserId=displayUserId;
        this.id = id;
        this.username = username;
        this.password = password;
        this.authorities = authorities;
        this.enabled = enabled;
        this.userType = userType;
        this.companyCode = companyCode;
    }

    @JsonIgnore
    public Long getId() {
        return id;
    }

    @JsonIgnore
    public String getDisplayUserId() {
        return displayUserId;
    }

    @JsonIgnore
    public Integer getUserType(){
        return userType;
    }

    @Override
    public String getUsername() {
        return username;
    }

    @JsonIgnore
    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @JsonIgnore
    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @JsonIgnore
    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }


    @JsonIgnore
    @Override
    public String getPassword() {
        return password;
    }

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return authorities;
    }

    @Override
    public boolean isEnabled() {
        return enabled;
    }

    public String getCompanyCode() {
        return companyCode;
    }
}

